<template>
  <div class="app-container">

    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-input v-model="listQuery.checkNo" clearable class="filter-item" style="width: 200px;"
        :placeholder="$t('Shop_check_no')" />
      <el-date-picker v-model="listQuery.startDate" class="filter-item" type="date" value-format="yyyy-MM-dd"
        :placeholder="$t('Start_time')"></el-date-picker>
      <el-date-picker v-model="listQuery.endDate" class="filter-item" type="date" value-format="yyyy-MM-dd"
        :placeholder="$t('End_time')"></el-date-picker>

      <el-select v-model="listQuery.shopId" clearable :placeholder="$t('请选择门店')" class="filter-item">
        <el-option v-for="item in shops" :key="item.id" :label="item.name" :value="item.id">
        </el-option>
      </el-select>

      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">{{ $t('Search') }}
      </el-button>
      <el-button v-permission="['GET /admin/p/stock_storecheck_add']" class="filter-item" type="primary"
        icon="el-icon-plus" @click="openAddCheck">{{ $t('Shop_check_add') }}</el-button>
    </div>

    <!-- 查询结果 -->
    <el-table ref="table" v-loading="listLoading" :data="list" :element-loading-text="$t('Searching')" border fit
      highlight-current-row>

      <el-table-column type="index" :index="getIndex" width="50"></el-table-column>

      <el-table-column align="center" min-width="100" :label="$t('门店名称')" prop="shopName" />

      <el-table-column align="center" min-width="100" :label="$t('Shop_check_no')" prop="checkNo" />

      <el-table-column align="center" :label="$t('Shop_check_user')" prop="checkUserName" />

      <el-table-column align="center" :label="$t('Shop_check_time')" prop="checkTime" />


      <el-table-column :label="$t('Operate')">
        <template slot-scope="scope">
          <el-button size="mini" type="info" @click="openDetail(scope.row)">{{ $t('View_details') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
      @pagination="getList" />
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import { shopCheckList, getShopAll } from '@/api/shop'
import { MessageBox } from 'element-ui'

export default {
  name: 'ShopCheck',
  components: { Pagination },
  data() {
    return {
      total: 0,
      listLoading: false,
      downloadLoading: false,
      listQuery: {
        page: 1,
        limit: 20,
        shopId: undefined,
        checkNo: undefined,
        startDate: undefined,
        endDate: undefined,
        sort: 'add_time',
        order: 'desc'
      },
      list: [],
      shops: [],
    }
  },
  created() {
    if (this.$route.query.shopId) {
      this.listQuery.shopId = this.$route.query.shopId
    }
    this.getList()
    getShopAll().then(res =>{
      const response = res.data.data;
      this.shops = response;
      // console.log(response);
    })
  },
  methods: {
    getList() {
      shopCheckList(this.listQuery).then(res => {
        this.list = res.data.data.list
        this.total = res.data.data.total
      }).catch(() => {
        this.list = []
        this.listLoading = false
      })
    },
    handleFilter() {
      this.getList()
    },
    openAddCheck() {
      this.$router.push({ path: '/repository/shopCheck/add' })
    },
    openDetail(row) {
      this.$router.push({ path: '/repository/shopCheck/detail', query: { id: row.id } })
    },
    getIndex(index) {
      return (index + 1) + (this.listQuery.page - 1) * this.listQuery.limit;
    }
  }
}
</script>

<style scoped>

</style>
